//
//  FBtMessageModel.h
//  JwPack
//
//  Created by 陈警卫 on 2025/7/28.
//

#import <Foundation/Foundation.h>

#import "FBtSignal.h"
#import "FBtCorer.h"
#import "FBtExten.h"

typedef NS_ENUM(NSUInteger, FBtMessageState) {
    FBtMessageStatePlain, // 默认
    FBtMessageStateSended, // 发送
    FBtMessageStateTimeout, // 超时
};

typedef NS_ENUM(NSUInteger, FBtMessageLevel) {
    FBtMessageLevelPlain, // 默认
    FBtMessageLevelPrior, // 优先
};

typedef NS_ENUM(NSUInteger, FBtMessageWriteType) {
    FBtMessageWriteTypePlain, // 默认
    FBtMessageWriteTypeWithoutResponse,
    FBtMessageWriteTypeResponse,
};

@interface FBtMessageModel : NSObject

@property (nonatomic, assign) FBtMessageState state;
@property (nonatomic, assign) FBtMessageLevel level;
@property (nonatomic, assign) FBtMessageWriteType writeType;

@property (nonatomic, strong) FBtPeriModel *periModel;

// key

@property (nonatomic, strong) NSString *key;

// 发送

@property (nonatomic, assign) FBtSig signal;
@property (nonatomic, strong) NSData *valueData;

@property (nonatomic, assign) UInt8 func;
@property (nonatomic, assign) UInt8 type;
@property (nonatomic, assign) UInt16 length;
@property (nonatomic, strong) NSData *timeData;

@property (nonatomic, strong) NSData *data; // 完整数据

// 接收

@property (nonatomic, strong) NSData *r_value;
@property (nonatomic, strong) NSData *r_data; // 完整发送数据

// 解析

@property (nonatomic, strong) NSDictionary *r_decode;

// tool

@property (nonatomic, strong) NSTimer *timer;
@property (nonatomic, assign) CGFloat timeout;

// 回调

/// 数据回调
@property (nonatomic, copy) void(^didReceiveAction)(FBtMessageModel *messageModel);

/// 配置完成数据
- (void)setupCompleData;

- (void)startTimer:(void(^)(FBtMessageModel *messageModel))didTimeoutAction;


@end

